package org.jeecg.modules.friends.handler;

import java.util.Map;

import org.jeecg.common.exception.MakeFriendsBaseException;
import org.springframework.beans.factory.InitializingBean;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractTradeOrderHandler implements InitializingBean {
    private static final Map<String, AbstractTradeOrderHandler> HANDLER_MAP = Maps.newHashMap();


    @Override
    public void afterPropertiesSet() throws Exception {
        HANDLER_MAP.put(eventType(), this);
    }

    public abstract String eventType();


    public abstract boolean doDispatch(String eventType, String entity);

    public boolean doIntercept(String eventType, String entity) {
        return false;
    }

    public static boolean processDispose(String eventType, String entity) {
        AbstractTradeOrderHandler disposeTemplateHandler = HANDLER_MAP.get(eventType);
        if (disposeTemplateHandler == null) {
            log.error("处置执行，未匹配到具体的处理器,eventType={}", eventType);
            throw new MakeFriendsBaseException("处置执行，未匹配到具体的处理器");
        }
        return disposeTemplateHandler.doDispatch(eventType, entity);
    }

}